package com.woniu.rear.comm.web.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.woniu.rear.comm.core.code.ResponseEnum;
import com.woniu.rear.comm.core.dto.ResponseEntity;
import com.woniu.rear.comm.core.exception.RearException;

import lombok.extern.slf4j.Slf4j;

/**
   *   全局异常处理
 * @author liwei
 *
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
	
	@ExceptionHandler(RearException.class)
	@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
	public ResponseEntity<?> rearHandler(RearException e) {
		log.error("error:",e);
		return new ResponseEntity<>(e.getCode(),e.getMessage());
	}
	
	@ExceptionHandler(Exception.class)
	@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
	public ResponseEntity<?> exerHandler(Exception e) {
		log.error("error:",e);
		return new ResponseEntity<>(ResponseEnum.RES_ERROR.getCode(),e.getMessage());
	}

}
